package com.example.teaculture.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.annotation.Nullable;

import com.example.teaculture.R;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;

public class DataFragment extends androidx.fragment.app.Fragment {
    private FloatingActionButton mfab;
    BarChart barChart;
    PieChart pieChart;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.data_fragment, container, false);
        mfab = (FloatingActionButton)view.findViewById(R.id.fab);
        barChart = view.findViewById(R.id.bar_chart);
        pieChart = view.findViewById(R.id.pie_chart);

        ArrayList<BarEntry> barEntries = new ArrayList<>();
        ArrayList<PieEntry> pieEntries = new ArrayList<>();



        barEntries.add(new BarEntry(2013,(float) (188.73)));
        pieEntries.add(new PieEntry((float) (188.73)));

        barEntries.add(new BarEntry(2014,(float) (204.93)));
        pieEntries.add(new PieEntry((float) (204.93)));

        barEntries.add(new BarEntry(2015,(float) (227.66)));
        pieEntries.add(new PieEntry((float) (227.66)));

        barEntries.add(new BarEntry(2016,(float) (231.33)));
        pieEntries.add(new PieEntry((float) (231.33)));

        barEntries.add(new BarEntry(2017,(float) (246.04)));
        pieEntries.add(new PieEntry((float) (246.04)));

        barEntries.add(new BarEntry(2018,(float) (261.04)));
        pieEntries.add(new PieEntry((float) (264.04)));

        barEntries.add(new BarEntry(2019,(float) (277.72)));
        pieEntries.add(new PieEntry((float) (277.72)));

        barEntries.add(new BarEntry(2020,(float) (293.18)));
        pieEntries.add(new PieEntry((float) (293.18)));

        barEntries.add(new BarEntry(2021,(float) (316.4)));
        pieEntries.add(new PieEntry((float) (316.4)));

        barEntries.add(new BarEntry(2022,(float) (335)));
        pieEntries.add(new PieEntry((float) (335)));

        BarDataSet barDataSet = new BarDataSet(barEntries,"年茶叶产量");
        barDataSet.setColors(Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0),
                Color.rgb(106, 150, 31), Color.rgb(179, 100, 53),Color.rgb(0,255,255),
                Color.rgb(255,0,255),Color.rgb(0,0,255),Color.rgb(255,235,205),Color.rgb(0,199,140));
        barChart.setData(new BarData(barDataSet));
        barChart.animateY(5000);
        barChart.getDescription().setPosition(1300,1370);
        barChart.getDescription().setText("2013-2022茶叶年产量/单位:万吨");
        barChart.getDescription().setTextColor(Color.BLUE);


        PieDataSet pieDataSet = new PieDataSet(pieEntries,"年茶叶产量");
        pieDataSet.setColors(Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0),
                Color.rgb(106, 150, 31), Color.rgb(179, 100, 53),Color.rgb(0,255,255),
                Color.rgb(255,0,255),Color.rgb(0,0,255),Color.rgb(255,235,205),Color.rgb(0,199,140));
        pieChart.setData(new PieData(pieDataSet));
        pieChart.animateXY(5000,5000);
        pieChart.getDescription().setText("2013-2022年茶叶产量/单位:万吨");
        pieChart.getDescription().setTextColor(Color.BLUE);

        return view;
    }
}
